package xjtu.zd.server.staff.login;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xjtu.zd.server.common.Result;
import xjtu.zd.server.common.TokenUtils;

import javax.annotation.Resource;

@RestController
@RequestMapping("/staff/login")
public class SLoginController {

    @Resource
    private SLoginService SLoginService;

    @RequestMapping("")
    public Result login(@RequestBody SLoginDto dto){

        boolean confirm = SLoginService.checkLogin(dto);

        if(confirm){
            String token = TokenUtils.loginSign(dto.getSta_id(),dto.getSta_pwd(),true);//token令牌中加入身份识别信息
            return Result.success((Object)token);
        }
        return Result.fail(Result.ERR_CODE_BUSINESS,"用户名或密码错误！");
    }

}
